snapshot: Add api for radial gradients
authorMatthias Clasen <mclasen@redhat.com>
Sat, 12 Sep 2020 03:50:25 +0000 (23:50 -0400)
committerTimm Bäder <mail@baedert.org>
Fri, 18 Sep 2020 13:39:04 +0000 (15:39 +0200)
These are the equivalents of the linear gradient apis.

gtk/gtksnapshot.c
gtk/gtksnapshot.h

index 7de659416785388c5f169aec21daed941c4840d3..123bfcd773985a3eedf2b5c13877eb62eefaabee 100644 (file)
@@ -1967,6 +1967,82 @@ gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot            *snapshot,
   gtk_snapshot_append_node_internal (snapshot, node);
 }
 
+void
+gtk_snapshot_append_radial_gradient (GtkSnapshot            *snapshot,
+                                     const graphene_rect_t  *bounds,
+                                     const graphene_point_t *center,
+                                     float                   radius,
+                                     float                   scale,
+                                     float                   start,
+                                     float                   end,
+                                     const GskColorStop     *stops,
+                                     gsize                   n_stops)
+{
+  GskRenderNode *node;
+  graphene_rect_t real_bounds;
+  graphene_point_t real_center;
+  float scale_x, scale_y, dx, dy;
+
+  g_return_if_fail (snapshot != NULL);
+  g_return_if_fail (center != NULL);
+  g_return_if_fail (stops != NULL);
+  g_return_if_fail (n_stops > 1);
+
+  gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
+  gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
+  real_center.x = scale_x * center->x + dx;
+  real_center.y = scale_y * center->y + dy;
+
+  node = gsk_radial_gradient_node_new (&real_bounds,
+                                       &real_center,
+                                       radius,
+                                       scale,
+                                       start,
+                                       end,
+                                       stops,
+                                       n_stops);
+
+  gtk_snapshot_append_node_internal (snapshot, node);
+}
+
+void
+gtk_snapshot_append_repeating_radial_gradient (GtkSnapshot            *snapshot,
+                                               const graphene_rect_t  *bounds,
+                                               const graphene_point_t *center,
+                                               float                   radius,
+                                               float                   scale,
+                                               float                   start,
+                                               float                   end,
+                                               const GskColorStop     *stops,
+                                               gsize                   n_stops)
+{
+  GskRenderNode *node;
+  graphene_rect_t real_bounds;
+  graphene_point_t real_center;
+  float scale_x, scale_y, dx, dy;
+
+  g_return_if_fail (snapshot != NULL);
+  g_return_if_fail (center != NULL);
+  g_return_if_fail (stops != NULL);
+  g_return_if_fail (n_stops > 1);
+
+  gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
+  gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
+  real_center.x = scale_x * center->x + dx;
+  real_center.y = scale_y * center->y + dy;
+
+  node = gsk_repeating_radial_gradient_node_new (&real_bounds,
+                                                 &real_center,
+                                                 radius,
+                                                 scale,
+                                                 start,
+                                                 end,
+                                                 stops,
+                                                 n_stops);
+
+  gtk_snapshot_append_node_internal (snapshot, node);
+}
+
 /**
  * gtk_snapshot_append_border:
  * @snapshot: a #GtkSnapshot
index 406a02da5818d181e4aef45374d0d2cc375c156b..9be3382a5239240085d0857c04e3f5e24bc08f4e 100644 (file)
@@ -165,6 +165,26 @@ void            gtk_snapshot_append_repeating_linear_gradient (GtkSnapshot
                                                                const GskColorStop     *stops,
                                                                gsize                   n_stops);
 GDK_AVAILABLE_IN_ALL
+void            gtk_snapshot_append_radial_gradient     (GtkSnapshot            *snapshot,
+                                                         const graphene_rect_t  *bounds,
+                                                         const graphene_point_t *center,
+                                                         float                   radius,
+                                                         float                   scale,
+                                                         float                   start,
+                                                         float                   end,
+                                                         const GskColorStop     *stops,
+                                                         gsize                   n_stops);
+GDK_AVAILABLE_IN_ALL
+void            gtk_snapshot_append_repeating_radial_gradient (GtkSnapshot            *snapshot,
+                                                               const graphene_rect_t  *bounds,
+                                                               const graphene_point_t *center,
+                                                               float                   radius,
+                                                               float                   scale,
+                                                               float                   start,
+                                                               float                   end,
+                                                               const GskColorStop     *stops,
+                                                               gsize                   n_stops);
+GDK_AVAILABLE_IN_ALL
 void            gtk_snapshot_append_border              (GtkSnapshot            *snapshot,
                                                          const GskRoundedRect   *outline,
                                                          const float             border_width[4],